package com.hsnn.medstgmini.pro.plan.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.service.DicDrugspecManager;
import com.hsnn.medstgmini.dao.DynamicSelectDao;
import com.hsnn.medstgmini.pro.plan.model.BasePriceadjplan;
import com.hsnn.medstgmini.pro.plan.service.BasePriceadjplanManager;
import com.hsnn.medstgmini.pro.plan.service.BasePriceadjplandetailManager;
import com.hsnn.medstgmini.pro.plan.service.PricePlanManager;
import com.hsnn.medstgmini.pro.project.model.BidProject;
import com.hsnn.medstgmini.pro.project.service.BidProjectManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.Pagination;

@Controller
@RequestMapping("/basePriceadjplandetail")
public class BasePriceadjplandetailController {

	private static final Logger log = Logger.getLogger(BasePriceadjplandetailController.class);

	@Autowired
	private BasePriceadjplandetailManager basePriceadjplandetailManager;

	@Autowired
	private BasePriceadjplanManager basePriceadjplanManager;

	@Autowired
	private DicDrugspecManager dicDrugspecManager;

	@Autowired
	private DynamicSelectDao selectDao;

	@Autowired
	private PricePlanManager pricePlanManager;

	@Autowired
	private BidProjectManager bidProjectManager;
	
	@Autowired
	private HttpSession session;
	
	private SysUser getUser(){
		return (SysUser) session.getAttribute(Constants.USERINFO);
	}
	/**
	 * @category 跳转到明细列表页面
	 * @author 韩守松
	 * @date 2015年6月18日
	 * @param @param request
	 * @param @return
	 */
	@RequestMapping(value = "/toListJsp", method = { RequestMethod.GET, RequestMethod.POST })
	public String toListJsp(HttpServletRequest request, BasePriceadjplan basePriceadjplan, Pagination page) {
        List<BidProject> projList = bidProjectManager.getBidProjectSelectList(null, null);
		String priceAdjPlanId = request.getParameter("priceAdjPlanId");
		BasePriceadjplan plan = new BasePriceadjplan();
		if (StringUtils.isNotEmpty(priceAdjPlanId)) {
			plan = pricePlanManager.getPricePlanById(priceAdjPlanId);
			request.setAttribute("projList", projList);
			request.setAttribute("plan", plan);
			request.setAttribute("priceAdjPlanId", priceAdjPlanId);
		}
		return "/pro/price/priceChangeShow";
	}

	/**
	 * 调价明细列表
	 * 
	 * 用来封装json
	 * 
	 * @param request
	 * @param result
	 * @return
	 */
	@RequestMapping("/getDataList")
	@ResponseBody
	public Pagination getDataList(HttpServletRequest request) {
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("projName", request.getParameter("projName"));	
		page.getConditions().put("priceid", request.getParameter("priceAdjPlanId"));
		
		try {
				basePriceadjplandetailManager.getPriceDurgList(page);// 获取调价明细列表数据
		} catch (Exception e) {
			log.error("转为JSON对象异常", e);
		} catch (Error error) {
			log.error("转为JSON对象错误", error);
		}
		return page;
	}

	@RequestMapping(value = "/toHistoryListJsp", method = { RequestMethod.GET, RequestMethod.POST })
	public String toHistoryListJsp(HttpServletRequest request) {
        List<BidProject> projList = bidProjectManager.getBidProjectSelectList(null, null);
        request.setAttribute("projList", projList);
		return "/pro/price/priceChangeExeDetail";
	}

	/**
	 * 调价明细列表
	 * 
	 * 用来封装json
	 * 
	 * @param request
	 * @param result
	 * @return
	 */
	@RequestMapping(value = "/getHistoryDataList", method = {RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Pagination getHistoryDataList(HttpServletRequest request) {

		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("prodComp", request.getParameter("prodComp"));
		page.getConditions().put("projName", request.getParameter("projName"));
		page.getConditions().put("startTime", request.getParameter("startTime"));
		page.getConditions().put("endTime", request.getParameter("endTime"));
		page.getConditions().put("projName", request.getParameter("projName"));
		page.getConditions().put("orgId", getUser().getOrgId());
		try {
			basePriceadjplandetailManager.getHistoryDataList(page);// 获取历史调价信息
		} catch (Exception e) {
			log.error("转为JSON对象异常", e);
		} catch (Error error) {
			log.error("转为JSON对象错误", error);
		}
		return page;
	}
}